package com.extra_archive.project.iisu.view 
{
	import com.extra_archive.framework.core.mvc.model.IModel;
	import com.extra_archive.framework.core.mvc.view.ComponentView;
	import com.extra_archive.framework.core.mvc.view.IComponentView;
	import com.extra_archive.framework.utils.ArrayUtils;

	import org.papervision3d.cameras.CameraType;
	import org.papervision3d.view.BasicView;

	import flash.events.Event;

	/**
	 * @author vkimone
	 */
	public class BasicSpace3DView extends BasicView implements IComponentView 
	{
		protected var _model : IModel;
		
		private var _children : Array = new Array();

		public function BasicSpace3DView(model : IModel = null)
		{
			super(1024, 768, false, false, CameraType.TARGET);
			
			_model = model;
			
			setupCamera();
		}

		//--------------------------------------------------------------------------
		//
		//    Public Methods
		//
		//--------------------------------------------------------------------------

		public function initialize() : void 
		{
		}

		public function addComponent(component : IComponentView) : void 
		{
			_children.push(component);
		}

		public function removeComponent(component : IComponentView) : void 
		{
			ArrayUtils.removeElement(_children, component);
		}

		/**
		 * mdeiator view 에서 실행시킴
		 */
		public function update(event : Event = null) : void 
		{
			for each(var component:IComponentView in _children) 
			{
				component.update();
			}
			
			singleRender();
		}

		public function getChild(index : int) : ComponentView 
		{                           
			return this.getChildAt(index) as ComponentView;
		}

		//--------------------------------------------------------------------------
		//
		//    Private Methods
		//
		//--------------------------------------------------------------------------

		protected function setupCamera() : void 
		{
			// Math.abs(camera.z - obj.z) / camera.focus == camera.zoom;
			camera.z = -1000;
			camera.focus = 100;
			camera.zoom = 10;
			camera.useCulling = true;
			camera.useClipping = true;
			//camera.target = null;
		}
	}
}
